package com.iretailer.quartz.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class LoadTask implements CommandLineRunner {

	private final Logger log = LoggerFactory.getLogger(LoadTask.class);

	@Resource
	private QuartzService quartzService;
	//下面这个方法和 MyMapper冲突
//	@PostConstruct//这里的注解是 加载的时候就执行这个方法
//	public void  initTask() throws SchedulerException {
//		List<QuartzJobBean> taskList = quartzService.getTaskList();
//		log.info("初始化加载定时任务......");
//		for (QuartzJobBean job : taskList) {
//			quartzService.addJob(job);
//		}
//	}

    @Override
    public void run(String... args) throws Exception {

            List<QuartzJobBean> taskList = quartzService.getTaskList();
            log.info("Initializing load timed tasks(初始化加载定时任务)......");
            for (QuartzJobBean job : taskList) {
                quartzService.addJob(job);
            }
    }
}
